/**
 * Created by 张捉妖师 on 21/10/10.
 */

/**
 * @param {string} path
 * @returns {Boolean}
 */
export function isExternal(path) {
  return /^(https?:|mailto:|tel:)/.test(path);
}

/**
 * @description 验证手机号
 * @param {*} poneInput
 * @returns
 */
export function isPoneAvailable(poneInput) {
  var myreg = /^[1][3,4,5,7,8][0-9]{9}$/;
  if (!myreg.test(poneInput)) {
    return false;
  } else {
    return true;
  }
}
/**
 * @description 验证邮箱
 * @param {*} emailInput
 * @returns
 */
export function isEmailAvailable(emailInput) {
  var myreg = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
  if (!myreg.test(emailInput)) {
    return false;
  } else {
    return true;
  }
}
/**
 * @param {string} str
 * @returns {Boolean}
 */
export function validUsername(str) {
  // const valid_map = ['admin', 'editor']
  // return valid_map.indexOf(str.trim()) >= 0
  return true;
}

export function rewirteLog() {
  console.log = (function (log) {
    // eslint-disable-next-line eqeqeq
    return process.env.NODE_ENV == 'development' ? log : function () { }
  }(console.log))
}

export function dateToFormat (originDate) {
  if (!originDate) return
  const dt = new Date(originDate);
  const y = dt.getFullYear();
  const m = (dt.getMonth() + 1 + "").padStart(2, "0");
  const d = (dt.getDate() + "").padStart(2, "0");

  const hh = (dt.getHours() + "").padStart(2, "0");
  const mm = (dt.getMinutes() + "").padStart(2, "0");
  const ss = (dt.getSeconds() + "").padStart(2, "0");

  return `${y}-${m}-${d} ${hh}:${mm}:${ss}`;
}
export function dateToFormattwo(originDate) {
  if (!originDate) return
  const dt = new Date(originDate);
  const y = dt.getFullYear();
  const m = (dt.getMonth() + 1 + "").padStart(2, "0");
  const d = (dt.getDate() + "").padStart(2, "0");
  return `${y}-${m}-${d}`;
}
export function dateToFormatname(originDate) {
  if (!originDate) return
  const dt = new Date(originDate);
  const y = dt.getFullYear();
  const m = (dt.getMonth() + 1 + "").padStart(2, "0");
  const d = (dt.getDate() + "").padStart(2, "0");
  return `${y}年-${m}月-${d}日`;
}
export function dateToFormatthree(originDate) {
  if (!originDate) return
  const dt = new Date(originDate);
  const y = dt.getFullYear();
  const m = (dt.getMonth() + 1 + "").padStart(2, "0");
  // const d = (dt.getDate() + "").padStart(2, "0");
  return `${y}-${m}`;
}
// 判断水产养殖 不能出现病虫害
export function farmingTypeTitle() {
  let farmingTypeNo = sessionStorage.farmingTypeNo;
  console.log(farmingTypeNo)
  if (farmingTypeNo === "sc") {
    return "病害";
  } else if (farmingTypeNo === "gc") {
    return "病害";
  } else {
    return "病虫害";
  }
}
// 点击跳转对应地方
export function toLocal(loc) {
  let toElement = document.getElementById(loc)
  toElement.scrollIntoView({
    behavior: "smooth", // 平滑过渡
    block: "start" // [可选] "start"，"center"，"end"或"nearest"。默认为"center"
  })
}
// 获取一年  所有周
export function AllWeeks(year) {
  var d = new Date(year, 0, 1);
  let WeekList = []
  while (d.getDay() !== 1) {
    d.setDate(d.getDate() + 1);
  }
  let to = new Date(year + 1, 0, 1);
  var i = 1;
  // eslint-disable-next-line no-unmodified-loop-condition
  for (let from = d; from < to;) {
    WeekList[i - 1] = {
      startDate: year + '-' + ((from.getMonth() + 1) < 10 ? ('0' + (from.getMonth() + 1)) : (from.getMonth() + 1)) + '-' + ((from.getDate()) < 10 ? ('0' + (from.getDate())) : (from.getDate())),
      endDate: '',
      name: i + "周"
    }
    from.setDate(from.getDate() + 6);
    if (from < to) {
      from.setDate(from.getDate() + 1);
      WeekList[i - 1]['endDate'] = year + '-' + ((from.getMonth() + 1) < 10 ? ('0' + (from.getMonth() + 1)) : (from.getMonth() + 1)) + '-' + ((from.getDate()) < 10 ? ('0' + (from.getDate())) : (from.getDate()))
    } else {
      to.setDate(to.getDate() - 1);
      WeekList[i - 1]['endDate'] = year + '-' + ((from.getMonth() + 1) < 10 ? ('0' + (from.getMonth() + 1)) : (from.getMonth() + 1)) + '-' + ((from.getDate()) < 10 ? ('0' + (from.getDate())) : (from.getDate()))
    }
    i++;
  }
  return WeekList
}
// 获取一年  所有月
export function AllMonths(year) {
  let MonthsList = []
  for (var i = 1; i < 13; i++) {
    MonthsList.push({
      startDate: year + '-' + (i < 10 ? ('0' + i) : i) + '-' + '01',
      endDate: year + '-' + (i < 10 ? ('0' + i) : i) + '-' + (new Date(year, i, 0).getDate()),
      name: i + "月"
    })
  }
  return MonthsList
}
// 获取批量年份
export function AllYears(smallYears = 1949) {
  // 获取当前时间
  var date = new Date();
  let yearsData = []
  let nowYears = date.getFullYear()
  var Years = nowYears - smallYears
  // console.log(nowYears, Years);
  var arrYear = [];
  for (var i = 0; i <= Years; i++) {
    arrYear.push(nowYears--)
  }
  arrYear.forEach(ele => {
    // 下拉框的数组
    yearsData.push({
      value: ele,
      label: ele + '年'
    })
  })
  return yearsData
}
